<template>
  <div class="company-list-1">
    <div class="header">
      <div class="prefix"></div>
      <div class="header-title"><span>告警列表</span><span>更多></span></div>
    </div>
    <div class="content">
      <el-table
        ref="myTable"
        :data="info"
        :row-style="{ height: '20px' }"
        :cell-style="{ padding: '0px' }"
        style="width: 480px; height: 280px"
        :header-cell-style="{ 'text-align': 'center' }"
        :row-class-name="tableRowClassName"
        @mouseover.native="clearScroll"
        @mouseleave.native="createScroll"
      >
        <el-table-column label="#" width="40" align="center">
          <template #default="{ $index }">
            {{ $index + 1 }}
          </template>
        </el-table-column>
        <el-table-column prop="rearerName" width="80" label="养户" align="center" />
        <el-table-column prop="alarmEvent" width="110" label="生物安全事件" align="center">
          <template #default="scope">
            {{ alarmEventMap[scope.row.alarmEvent] || '-' }}
          </template>
        </el-table-column>
        <el-table-column prop="alarmTime" width="130" label="告警时间" align="center" />
        <el-table-column prop="alarmStatus" width="100" label="状态" align="center">
          <template #default="scope">
            <el-tag
              :type="scope.row.alarmStatus === '已派单' ? 'success' : 'primary'"
              effect="dark"
              size="small"
              >{{ scope.row.alarmStatus }}
            </el-tag>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import { useTableScrollAndRowClass } from '@/composables/useTableScrollAndRowClass'
const { info } = defineProps({
  info: {
    type: Object,
    default: () => {}
  }
})

const alarmEventMap = {
  1: '空栏巡查',
  2: '肉猪饲养巡查',
  3: '生物资产端到端',
  4: '生物安全巡查',
  5: '肉猪健康巡查'
}

// 使用 Hook
const { tableRowClassName, createScroll, clearScroll, myTable } = useTableScrollAndRowClass()

onMounted(() => {
  createScroll()
})

onUnmounted(() => {
  clearScroll()
})
</script>

<style scoped lang="scss">
@import '@/assets/table.css';

.company-list-1 {
  padding: 10px;
  width: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  margin-bottom: 20px;
  font-size: 16px;

  .header {
    width: 100%;
    height: 50px;
    display: flex;
    align-items: center;
    padding-left: 20px;

    .prefix {
      width: 8px;
      height: 15px;
      background-color: #31a7ff;
    }

    .header-title {
      padding-left: 10px;
      display: flex;
      flex: 1;
      justify-content: space-between;
    }
  }

  .content {
    flex: 1;
    display: flex;
    justify-content: space-between;
    padding: 0 10px;

    &-item1 {
      width: 150px;
      height: 150px;
      background-position: center, center;
      background-repeat: no-repeat, no-repeat;
      background-size: cover, cover;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;

      &-title {
        line-height: 30px;
      }

      &-value {
        font-weight: bold;
        font-size: 24px;
      }
    }

    .bg-green {
      background-image: url('@/assets/green1.svg'), url('@/assets/green2.svg');
    }

    .bg-blue {
      background-image: url('@/assets/blue1.svg'), url('@/assets/blue2.svg');
    }

    .bg-orange {
      background-image: url('@/assets/orange1.svg'), url('@/assets/orange2.svg');
    }
  }
}
</style>
